<template>
  <div class="app-container">
    <eHeader :param-bean="paramBean" :sup_this="sup_this" />
    <eForm ref="form" :sup_this="sup_this" />
    <PrintBarcodePage ref="printBarcodePage" :sup_this="sup_this" barcode-print-type="EAN-13" />
    <XlsImportForm ref="XlsImportForm" :import-url="importUrl" :import-template-url="importTemplateUrl" :sup_this="sup_this" />
    <!--表格渲染-->
    <DataGridTable
      v-loading="loading"
      ref="mainTable"
      :sup_this="sup_this"
      :data="data.rtnList"
      :max-height="gridMaxHeight"
      :total="total"
      :all-define-columns="['catName','thirdCode','itemName','itemBrand','itemSpec','customCode','stockUnit','warehouseId','accountCode','safetyStock','lotType','taxRate','itemType','unitPrice','salePrice','vipSalePrice','batchSalePrice','saleFlag','lastUpdateDate','attribute3','attribute4','attribute5','attribute6',]"
      grid-id="baseItemMngProcessGridId"
      @selection-change="handleGridSelectionChange">
      <DataGridColumnSlot prop="itemCode" label="物料编码">
        <template slot-scope="scope">
          <edit :data="scope.row" :sup_this="sup_this" />
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="catName" prop="catName" label="物料类别" />
      <DataGridColumn slot="itemName" prop="itemName" label="物料名称" />
      <DataGridColumn slot="itemSpec" prop="itemSpec" label="规格" />
      <DataGridColumn slot="itemBrand" prop="itemBrand" label="品牌" />
      <DataGridColumn slot="customCode" prop="customCode" label="客户编码" />
      <DataGridColumnSlot slot="stockUnit" prop="stockUnit" label="库存单位">
        <template slot-scope="scope">
          <template v-for="item in dicts.item_unit">
            <span v-if="scope.row.stockUnit.toString() === item.dictCode" :key="item.id" >{{ item.dictName }}</span>
          </template>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="safetyStock" prop="safetyStock" label="安全库存" />
      <DataGridColumn slot="taxRate" prop="taxRate" label="税率" />
      <DataGridColumnSlot slot="itemType" prop="itemType" label="物料属性">
        <template slot-scope="scope">
          <template v-for="item in dicts.item_type">
            <el-tag v-if="scope.row.itemType.toString() === item.dictCode" :key="item.id" :type="item.attribute1" >{{ item.dictName }}</el-tag>
          </template>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="unitPrice" prop="unitPrice" label="进货价" />
      <DataGridColumn slot="salePrice" prop="salePrice" label="销售价" />
      <DataGridColumn slot="vipSalePrice" prop="vipSalePrice" label="会员价" />
      <DataGridColumn slot="batchSalePrice" prop="batchSalePrice" label="批发价" />
      <DataGridColumn slot="saleFlag" prop="saleFlag" label="销售品" />
      <DataGridColumnSlot slot="lastUpdateDate" prop="lastUpdateDate" label="最后更新时间" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdateDate) }}</span>
        </template>
      </DataGridColumnSlot>
    </DataGridTable>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
import eForm from './module/form'
import initData from '@/mixins/initData'
import baseItem from '@/api/base/BaseItem'
import PrintBarcodePage from '@/views/components/PrintBarcodePage'

export default {
  components: { eHeader, eForm, edit, PrintBarcodePage },
  dictTypes: ['item_lot_type', 'item_type', 'item_unit'],
  mixins: [initData],
  props: {
  },
  data() {
    return {
      delLoading: false,
      sup_this: this,
      importUrl: baseItem.importUrl(),
      importTemplateUrl: baseItem.importTemplateUrl()
    }
  },
  created() {
    this.url = baseItem.loadDataUrl()
    this.$nextTick(() => {
      this.init()
    })
  },
  mounted() {
  },
  methods: {
    parseTime,
    checkPermission,
    async beforeInit() {
      return true
    }
  }
}
</script>
